import MonsterAssetStruct from "../Structs/MonsterAssetStruct";
import G from "../Utilities/Global";

/**
 * 怪物信息配表信息
 * created by Five on 2018-11-19 17:09:26
 */

export default class MonsterAssetConfig {
    public Assets: Map<Number, MonsterAssetStruct>;
    public AssetsArr: Array<MonsterAssetStruct>;

    constructor() {
        this.Assets = new Map<Number, MonsterAssetStruct>();
        this.AssetsArr = new Array<MonsterAssetStruct>();
        this.init();
    }

    private async init() {
        let asset = await G().Res.LoadFile("config/tables", "MonsterAssets") as cc.JsonAsset;
        let array = asset.json as Array<any>;
        array.forEach(struct => {
            let mas = struct as MonsterAssetStruct
            this.Assets.set(mas.id, mas);
            this.AssetsArr.push(mas);
        })
        cc.log(this.Assets)
    }

    public Get(id: number) {
        let mon = this.Assets.get(id);
        if (mon)
            return new MonsterAssetStruct(mon);
        return null;
    }

    public GetConfig(id: number) {
        return this.Assets.get(id);
    }
}